package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetDetailReportByTypeRequest;
import keeto.com.vn.bms.network.response.GetDetailReportbyTypeResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetDetailReportByType extends AbstractTask {
	private int Type;
	private String ObjId;
	private int SortBy;
	private String DateStart;
	private String DateEnd;
	private String AuthKey;


	public TaskGetDetailReportByType(BMSListener listener, IBMSCore core, int type,
			String objId, int sortBy, String dateStart, String dateEnd,
			String authKey) {
		super(listener, core);
		Type = type;
		ObjId = objId;
		SortBy = sortBy;
		DateStart = dateStart;
		DateEnd = dateEnd;
		AuthKey = authKey;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
	IOException {
		// TODO Auto-generated method stub
		GetDetailReportByTypeRequest request = new  GetDetailReportByTypeRequest();
		request.setType(Type);
		request.setObjId(ObjId);
		request.setSortBy(SortBy);
		request.setDateStart(DateStart);
		request.setDateEnd(DateEnd);
		request.setAuthKey(AuthKey);
		GetDetailReportbyTypeResponse response = protocol.getDetailReportbyType(request);
		for (BMSListener mlistener : listener){
			mlistener.finishGetDetailReportbyType(response.getReturnCode(), request.getType(), response.getListHospital(), response.getListDoctor());
		}
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishGetDetailReportbyType(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION,IBMSConfig.UNINITIALIZED_INT, null, null);
		}
	}

}
